<template>
  <div>
    <el-table :data="goodList" style="width: 100%">
      <el-table-column prop="id" label="商品编号"> </el-table-column>
      <el-table-column prop="goodsname" label="商品名称"> </el-table-column>
      <el-table-column prop="price" label="商品价格"> </el-table-column>
      <el-table-column prop="market_price" label="市场价格"> </el-table-column>
      <el-table-column prop="img" label="图片" width="180">
        <template slot-scope="obj">
          <img
            :src="'http://localhost:3000' + obj.row.img"
            alt=""
            style="width: 50px"
          />
        </template>
      </el-table-column>
      <el-table-column prop="isnew" label="是否新品">
        <template slot-scope="obj">
          <el-tag type="success" v-show="obj.row.isnew == 1">是</el-tag>
          <el-tag type="danger" v-show="obj.row.isnew == 2">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否热卖">
        <template slot-scope="obj">
          <el-tag type="success" v-show="obj.row.ishot == 1">是</el-tag>
          <el-tag type="danger" v-show="obj.row.ishot == 2">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="obj">
          <el-tag type="success" v-show="obj.row.status == 1">启用中</el-tag>
          <el-tag type="danger" v-show="obj.row.status == 2">已禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200px">
        <template slot-scope="obj">
         <el-button type="primary" @click="updataGoods(obj.row.id)">编辑</el-button>
        <el-button type="danger" @click="del(obj.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="size"
      :total="total"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>

<script>
import {goodsdelete} from '../../request/api.js'
import { successMsg, failedMsg } from "../../tools/tools.js";

export default {
  props: ["goodList", "size","total"],
  methods: {
    change(n) {
      this.$emit("changePage", n);
    },
    updataGoods(id){
      this.$emit('updataGoods',id)
    },
    del(id){  
      goodsdelete({id}).then(d=>{
        if(d.data.code == 200){
          successMsg('删除成功')
          this.$emit('deleteGoodes')
        }else{
          failedMsg('删除失败')
        }
      })
    }
  },
};
</script>

<style>
.cell {
  text-align: center !important;
}
.el-pagination {
  text-align: right;
}
</style>